# Author:Zhang Yu

import pika
import sys
connection = pika.BlockingConnection(pika.ConnectionParameters("127.0.0.1"))
channel = connection.channel()
channel.exchange_declare(exchange="topic_logs",exchange_type='topic')

result = channel.queue_declare(queue="topic_logs")
queue_name = result.method.queue

binding_keys = sys.argv[1:]
if not binding_keys:
    sys.stderr.write("usage: %s[binding_key]"%sys.argv[0])
    sys.exit(1)
for binding_key in binding_keys:
    channel.queue_bind(exchange="topic_logs",
                       queue=queue_name,
                       routing_key=binding_key)
print("[*] 等待日志")

def callback(ch,method,properties,body):
    print("[X]",method.routing_key,body)
channel.basic_consume(on_message_callback=callback,queue=queue_name,auto_ack=True)
channel.start_consuming()